package com.fish.yssb.ui.page.activity.setPara;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.fish.yssb.R;
import com.fish.yssb.ui.page.activity.base.BaseActivity;
import com.fish.yssb.ui.page.util.ToastUtil;
import com.fish.yssb.ui.page.util.TopToastUtil;
import com.fish.yssb.ui.page.widget.CustomDialog;
import com.fish.yssb.ui.page.widget.LoadingDialog;
import com.jaeger.library.StatusBarUtil;


/**
 * A login screen that offers login via email/password.
 */
public class SetParaOneActivity extends BaseActivity implements OnClickListener {
    private static final String TAG = SetParaListActivity.class.getSimpleName();


    EditText et_deveveid;
    EditText ed_msisdn;
    EditText et_ip;
    TextView tv_back, tv_save,et_cs,et_tcp,et_port,et_ip_bak,et_port_bak,et_apn,tv_set;
    private RelativeLayout ll_para_2, ll_para_3;
    private CustomDialog choosePicDialog;

    private int sevice_type,net_type;
    private Boolean  b_yz;

    public static void start(Context context) {
        Intent intent = new Intent(context, SetParaOneActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sevice_type = -1;
        net_type = -1;
        b_yz =false;
        StatusBarUtil.setTransparent(this);
        StatusBarUtil.setDarkMode(this);
        setContentView(R.layout.activity_setpara_one);
        initview();

        initData();

    }


    private void initData()
    {
        et_ip.setText("10.192.10.22");
        et_port.setText("8080");
        et_ip_bak.setText("10.192.10.23");
        et_port_bak.setText("8080");
        et_apn.setText("0");
        et_tcp.setText("TCP");
        et_cs.setText("");
        getYZ();

    }

    private void getYZ()
    {
        if(b_yz)
        {
            tv_save.setVisibility(View.GONE);
            tv_set.setTextColor(getResources().getColor(R.color.white));
        }else{
            tv_save.setVisibility(View.VISIBLE);
            tv_set.setTextColor(getResources().getColor(R.color.save_nosel));
        }
    }

    //初始化视图
    @SuppressLint("WrongViewCast")
    private void initview() {
        //登录层、下拉层、其它登录方式层

        tv_back = findViewById(R.id.tv_back);
        tv_save = findViewById(R.id.tv_save);
        et_ip = findViewById(R.id.et_ip);
        et_port = findViewById(R.id.et_port);
        et_apn = findViewById(R.id.et_apn);
        et_ip_bak = findViewById(R.id.et_ip_bak);
        et_port_bak = findViewById(R.id.et_port_bak);
        ll_para_2 = findViewById(R.id.ll_para_2);
        ll_para_3 = findViewById(R.id.ll_para_3);
        et_tcp = findViewById(R.id.et_tcp);
        et_cs = findViewById(R.id.et_cs);
        tv_set = findViewById(R.id.tv_set);


        tv_back.setOnClickListener(this);
        tv_save.setOnClickListener(this);
        tv_set.setOnClickListener(this);

        ll_para_2.setOnClickListener(this);
        ll_para_3.setOnClickListener(this);

    }

    private LinearLayout lyDlg;
    private TextView btn1, btn2, btnCancel;
    private Window window;

    @Override
    public void onClick(View view) {

        switch (view.getId()) {



            case R.id.ll_para_2:

                choosePicDialog = new CustomDialog(SetParaOneActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                 window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn1.setText("TCP");
                btn2.setText("UDP");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 1;
                        et_tcp.setText("TCP");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 2;
                        et_tcp.setText("UDP");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.ll_para_3:


                choosePicDialog = new CustomDialog(SetParaOneActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                 window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn1.setText("服务器");
                btn2.setText("客户端");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 1;
                        et_cs.setText("服务器");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 2;
                        et_cs.setText("客户端");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;
            case R.id.tv_back:
                finish();
                break;
            case R.id.tv_save:

                TopToastUtil.getInstance(this,R.layout.showdialog).showShortToast("认证成功");
                b_yz = true;
                getYZ();
                break;
            case R.id.tv_set:
                if(b_yz)
                {
                    TopToastUtil.getInstance(this,R.layout.showdialog).showShortToast("保存成功");
                }
                break;
            default:
                break;
        }


    }

}

